/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package models;
import myTest.MYTest;
import models.Skill.Skill;
import cstAndEnum.*;
import java.util.List;

/**
 *武将
 * @author Invince
 */
public class Role {
/*----------Attributs-------------------*/
    /**
     * 武将的id
     */
    protected int id;
    /**
     * 角色名称
     */
    protected String name;
    /**
     * 势力
     */
    protected FORCE force;
    /**
     * 血
     */
    protected int hp;
    /**
     * 技能列表
     */
    protected List<Skill> listSkill;
    /**
     * 主公技
     */
    protected List<Skill> listMajestySkill;
    protected String comments;

/*----------Public functions------------*/
    /**
     * 给角色添加技能
     * @param skill
     * @return
     */
    public boolean addSkill(Skill skill){
        String r="Role--addSkill:";
        boolean rb;
        if (listSkill.contains(skill)){
           rb= false;
           r="Failed: "+r+this.name+" addSkill "+skill.getName();
        }
        else {
            rb=listSkill.add(skill);
            r+=this.name+" addSkill "+skill.getName();
        }
        MYTest.println(r);
        return rb;
   }

    /**
     * 从角色中删除一个技能
     * @param skill
     * @return
     */
    public boolean deleteSkill(Skill skill){
       String r="Role--deleteSkill: ";
       boolean rb;
       if (!listSkill.contains(skill)){
          rb= false;
          r="Failed: "+r+this.name+" deleteSkill "+skill.getName();
       }
       else {
           rb=listSkill.remove(skill);
           r+=this.name+" deleteSkill "+skill.getName();
       }
       MYTest.println(r);
       return rb;
    }

    /**
     * 给角色添加主公技
     * @param skill
     * @return
     */
    public boolean addMajestySkill(Skill skill){
       String r="Role--addMajestySkill:";
       boolean rb;
       if (listMajestySkill.contains(skill)){
          rb= false;
          r="Failed: "+r+this.name+" addMajestySkill "+skill.getName();
       }
       else {
           rb=listMajestySkill.add(skill);
           r+=this.name+" addMajestySkill "+skill.getName();
       }
       MYTest.println(r);
       return rb;
    }

    /**
     * 从角色删除一个主公技
     * @param skill
     * @return
     */
    public boolean deleteMajestySkill(Skill skill){
       String r="Role--deleteMajestySkill:";
       boolean rb;
       if (!listMajestySkill.contains(skill)){
          rb= false;
          r="Failed: "+r+this.name+" deleteMajestySkill "+skill.getName();
       }
       else {
           rb=listMajestySkill.remove(skill);
           r+=this.name+" deleteMajestySkill "+skill.getName();
       }
       MYTest.println(r);
       return rb;
    }

    /**
     *
     * @param skill
     * @param targets
     * @param source
     * @param isMajesty
     * @return
     */
    public boolean castSkill(Skill skill,List<Player> targets,Player source, boolean isMajesty,Game game){
       String r="Role--castSkill: ";
       boolean rb;
       if(this.listSkill.contains(skill)){
           skill.cast(targets,source,game);
           r+=this.name+" cast "+skill.getName();
           rb=true;
       }
       else if(isMajesty && (this.listMajestySkill.contains(skill))){
           rb=skill.cast(targets,source,game);
           r+=this.name+" cast majesty Skill "+skill.getName();
       }
       else{
          r="Falied: "+r+skill.getName();
          rb=false;
       }
       MYTest.println(r);
       return rb;
    }

    /**
     * 比较两个武将是否是同一势力的
     * @param role
     * @return
     */
    public boolean isSameForce(Role role){
        if(role.getForce().equals(this.force)){
            MYTest.println("Role--isSameForce: yes");
            return true;
        }
         MYTest.println("Role--isSameForce: no");
        return false;
    }

        /**
     * 判断两个武将是否相等
     * @param obj
     * @return
     */
    @Override
    public boolean equals(Object obj){
        if(obj==null){
            return false;
        }
        if(!obj.getClass().equals(this.getClass())){
            return false;
        }
        else{
            Role rObj=(Role) obj;
            return (this.id==rObj.id);
        }
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 59 * hash + this.id;
        return hash;
    }



/*----------Constructor-----------------*/
    /**
     * Constructor
     * @param name
     * @param force
     * @param hp
     * @param comments
     */
    public Role(int id,String name, FORCE force, int hp, String comments) {
        this.id=id;
        this.name = name;
        this.force = force;
        this.hp = hp;
        this.comments = comments;
    }

    /**
     * Constructor with Majesty or Not
     * @param role
     * @param isMajesty
     */
    public Role(Role role, boolean isMajesty){
        this.id=role.getId();
        this.name=role.getName();
        this.comments=role.getComments();
        this.force=role.getForce();
        this.hp=role.getHp();
        this.setListMajestySkill(role.getListMajestySkill());
        this.setListSkill(role.getListSkill());
        if(isMajesty){
            this.hp++;
        }
    }

/*----------Gets and sets---------------*/
    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    public FORCE getForce() {
        return force;
    }

    public void setForce(FORCE force) {
        this.force = force;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public List<Skill> getListMajestySkill() {
        return listMajestySkill;
    }

    public void setListMajestySkill(List<Skill> listMajestySkill) {
        this.listMajestySkill = listMajestySkill;
    }

    public List<Skill> getListSkill() {
        return listSkill;
    }

    public void setListSkill(List<Skill> listSkill) {
        this.listSkill = listSkill;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    
}
